<?php

namespace App\Admin\Controllers;

use App\Admin\Repositories\WxNotice;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;

class WxNoticeController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new WxNotice('user'), function (Grid $grid) {
            $grid->model()->orderBy('id','desc');
//            $grid->column('id')->sortable();
            $grid->column('user.user_avatar', '用户头像')->image('', 50);
            $grid->column('user.user_name', '用户名');
            $grid->column('title');
            $grid->column('content')->limit(8);
            $grid->column('is_read')->using([0 => '用户未读', 1 => '用户已读'])->label([
                0 => 'red',
                1 => 'primary',
            ]);
            $grid->column('notice_type')->using([0 => '系统通知', 1 => '活动通知', 2 => '点赞通知', 3 => '收藏通知', 4 => '评论通知', 5 => '评论点赞通知', 8 => '发货通知'])->label([
                0 => 'blue',
                1 => 'primary',
                2 => 'red',
                3 => 'green',
                4 => 'orange2',
                5 => 'pink',
                8 => 'primary',
            ]);
            $grid->column('created_at');
            $grid->column('updated_at')->sortable();

            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('id');

            });

            $grid->disableCreateButton();
            $grid->disableActions();
            $grid->disableBatchDelete();

        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new WxNotice(), function (Show $show) {
            $show->field('id');
            $show->field('user_id');
            $show->field('posts_id');
            $show->field('title');
            $show->field('content');
            $show->field('is_read');
            $show->field('notice_type');
            $show->field('created_at');
            $show->field('updated_at');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new WxNotice(), function (Form $form) {
            $form->display('id');
            $form->text('user_id');
            $form->text('posts_id');
            $form->text('title');
            $form->text('content');
            $form->text('is_read');
            $form->text('notice_type');

            $form->display('created_at');
            $form->display('updated_at');
        });
    }
}
